<?php
/**
*作者：漫小猫
*QQ:2535080855
*Q群:536321009
*博客:www.lxbkw.com
*使用说明：将up主号ID改成自己的bilibili的up号就行了。
*/
class bilibili_user { 
    var $mid;//id
    var $name;//名字
    var $sex;//性别
  	var $level;//等级
	var $face;//头像
	var $sign;//签名
	var $top_photo;//背景
	var $vip_type;//VIP类型
    /* 成员函数 */
  function setMid($par){
     $this->mid = $par;
  }
  function getMid(){
     echo $this->mid . PHP_EOL;
  }
  //=======================
  function setName($par){
     $this->name = $par;
  }
  function getName(){
     echo $this->name . PHP_EOL;
  }
  //=======================
  function setSex($par){
     $this->sex = $par;
  }
  function getSex(){
     echo $this->sex . PHP_EOL;
  }
  //=======================
  function setFace($par){
     $this->face = $par;
  }
  function getFace(){
     echo $this->face . PHP_EOL;
  }
  //=======================
  function setSign($par){
     $this->sign = $par;
  }
  function getSign(){
     echo $this->sign . PHP_EOL;
  }
  //=======================
  function setTopPhoto($par){
     $this->top_photo = $par;
  }
  function getTopPhoto(){
     echo $this->top_photo . PHP_EOL;
  }
  //=======================
  function setVipType($par){
     $this->vip_type = $par;
  }
  function getVipType(){
     echo $this->vip_type . PHP_EOL;
  }
  //=======================
  function setLevel($par){
     $this->level = $par;
  }
  function getLevel(){
     echo $this->level . PHP_EOL;
  }
}
//curl链接服访问
function curl($durl){  
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_URL, $durl);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ;   
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ;  
    $data = curl_exec($ch);  
    curl_close($ch);  
    return $data;  
 }
//信息
function bilibili_user($up){
$axs = curl("https://api.bilibili.com/x/space/acc/info?mid=".$up."&jsonp=jsonp");
$json=json_decode($axs);
$data= $json->data;
$user = new bilibili_user;
$user->setMid($data->mid);
$user->setName($data->name);
$user->setSex($data->sex);
$user->setLevel($data->level);
$user->setFace($data->face);
$user->setSign($data->sign);
$user->setTopPhoto($data->top_photo);
$user->setVipType($data->vip->type);
return $user;
}
//追番
function bilibili_video_page($up,$page){
$axs = curl("https://space.bilibili.com/ajax/Bangumi/getList?mid=".$up."&page=".$page);
$json=json_decode($axs);
$data= $json->data->result;
$i=0;
$message = '';
foreach($data as $v){
$message .= '<div class="video"><a target="_blank" href="'.$v->share_url.'"><img src="'.$v->cover.'" title="'.$v->title.'"><p class="texta">'.$v->title.'</p></a><p class="textb">已'.$v->newest_ep_index.'集</p><p class="textc">'.$v->brief.'</p></div>';
}
echo $message;
}
//追番
function bilibili_video($up){
$axs = curl("https://space.bilibili.com/ajax/Bangumi/getList?mid=".$up);
$json=json_decode($axs);
//计算页数
$count= $json->data->count;
$count= $count/15;
if(is_int($count)){
  $page = $count;
  }else{
  $page = $count+1;  
  }
//循环取出
for ($i = 0; $i < $page; $i++) {
    bilibili_video_page($up,$i+1);
}
}

//收藏
function bilibili_fid($up){
  $axs = curl("https://api.bilibili.com/medialist/gateway/base/created?pn=1&ps=100&up_mid=".$up."&is_space=0&jsonp=jsonp");
  $json=json_decode($axs);
  $data= $json->data;
  return $data->list[0]->fid;
}
//收藏
function bilibili_collection_page($up,$page){
$axs=curl('https://api.bilibili.com/x/space/fav/arc?vmid='.$up.'&ps=30&fid='.bilibili_fid($up).'&tid=0&keyword=&pn='.$page.'&order=fav_time&jsonp=jsonp');
$jsondata = json_decode($axs);
$data=$jsondata->data->archives;
$i=0;
$message = '';
foreach($data as $v){
 $message .= '<div class="video"><a target="_blank" onclick="bilibili_video(\'https://player.bilibili.com/player.html?aid='.$v->aid.'\');" href="javascript:void(0);"><img src="'.$v->pic.'" title="'.$v->title.'"><p class="texta">'.$v->title.'</p></a><p class="textb">收藏于'.date("Y-m-d H:i:s",$v->fav_at).'</p></div>';
}
$message=str_replace("<em class=","",$message);
$message=str_replace("</em>","",$message);
$message=str_replace("\/","/",$message);
$message=str_replace(".gif@380w_240h_100Q_1c.webp",".gif",$message);
$message=str_replace("img src=\"http","img src=\"https",$message);
$message=str_replace("\keyword\>","",$message);
echo $message;
}
//收藏
function bilibili_collection($up){
$axs=curl('https://api.bilibili.com/x/space/fav/arc?vmid='.$up.'&ps=30&fid='.bilibili_fid($up).'&tid=0&keyword=&pn=1&order=fav_time&jsonp=jsonp');
$jsondata = json_decode($axs);
$page=$jsondata->data->pagecount;
for ($i = 0; $i < $page; $i++) {
    bilibili_collection_page($up,$i+1);
}
}
$av=$_GET['up'];
if($av!=''){
  $up=$av;//up主号ID
}else{
  $up='17093404';//up主号ID
}
//$up='34244383';
$user = bilibili_user($up);
?>
<!DOCTYPE html>
<!--
*作者：漫小猫
*QQ::2535080855
*Q群:536321009
*博客:www.lxbkw.com
-->
<html>
	<head>
		<meta charset="utf-8">
		<meta name="referrer" content="no-referrer" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0,viewport-fit=cover">
		<title>哔哩哔哩-<?php echo $user->getName();?></title>
	</head>
	<style>
		*{
			margin: 0;
			padding: 0;
		}
		html,body{
			width: 100%;
			height: 100%;
		}
		#user{
			width: 100%;
			height: 200px;
			background-repeat: no-repeat;
			background-position: center center;
			background-size: cover;
			background-image: url("http://i2.hdslb.com/bfs/space/6a1198e25f8764bd30d53411dac9fdf840bc3265.png");
		}
		#up{
			width: 320px;
			height: 100%;
			margin:auto auto;
			top: 0px;
			bottom: 0px;
		}
		#up_img{
			width: 80px;
			height: 80px;
			border-radius: 50px;
			background-color: aquamarine;
			margin:auto auto;
			top: 0px;
			bottom: 0px;
		}
		#up_img img{
			width: 80px;
			height: 80px;
			border-radius: 50px;
			text-align:center;
		}
		#up_img:hover{
			animation: mxm_img 1s linear infinite;
		}
		@keyframes mxm_img{
			from{transform: rotate(0deg);}
			to{transform: rotate(380deg);}
		}
		#up_xx{
			width: 100%;
			height: 100%;
		}
		#up_xx p{
			text-align: center;
			font-weight:800;
			font-size:15px;
		}
		#collection{
			width: 100%;
			height: 45%;
		}
		.video{
			width: 18%;
			height: 200px;
            margin-left:6%;
          	margin-bottom:6%;
			float: left;
		}
		.video a{
			text-decoration:none
		}
		.video a img{
			width: 80%;
			height: 80%;
			border:10px #000 double;
		}
		.texta{
			color: #000000;
			text-align: center;
			font-weight:800;
			font-size:14px;
		}
		.textb{
			color: #7FFFD4;
			text-align: center;
			font-weight:800;
			font-size:12px;
		}
		.textc{
			color: #000000;
			text-align: center;
			font-weight:800;
			font-size:10px;
		}
		#catchupwith{
			width: 100%;
			height: 45%;
            float: left;
          	margin-top:6%;
      }
      #b_video{
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			z-index: 9999;
		}
		#an{
			height: 30px;
			width: 100%;
			background-color: #ffffff;
		}
		#an img{
			float: right;
			margin-right: 10px;
            margin-top: 3px;
		}
      @media(max-width:768px){
        #user{
              height:180px;
        }
        #up_xx p {
   			 font-size: 11px;
		}
        .video a img{
    		height: 30%;
          	border: 5px #000 double;
        }
        .texta{
        	font-size: 10px;
        }
        .textb{
        	font-size: 8px;
        }
        .textc{
        	font-size: 8px;
        }
        #b_video{
          height: 95%;
        }
      }
	</style>
	<body>
		<div id="user">
			<div id="up">
			<div id="up_img">
				<img src="<?php echo $user->getFace();?>"/>
			</div>
			<div id="up_xx">
			<p>ID:<?php echo $user->getMid();?></p>
			<p>名字:<?php echo $user->getName();?></p>
			<p>性别:<?php echo $user->getSex();?></p>
			<p>VIP:<?php echo $user->getVipType();?></p>
			<p>等级:<?php echo $user->getLevel();?></p>
			<p>签名:<?php echo $user->getSign();?></p>
			    </div>
			</div>
		</div>
		<div id="collection">
			<h3>收藏</h3>
          <?php bilibili_collection($up);?>
		</div>
	
		<div id="catchupwith">
			<h3>追番</h3>
          <?php bilibili_video($up);?>
		</div>
      	<div id="b_video" hidden>
			<div id="an">
              <img onclick="no(3)" src="" width="25px" height="25px">
			  <img onclick="no(2)" src="" width="25px" height="25px">
			  <img onclick="no(1)" src="" width="25px" height="25px">
          </div>
			<iframe id="url" src="http://player.bilibili.com/player.html?aid=42509215" width="100%" height="100%" runat="server" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes"></iframe>
		</div>
	</body>
  	<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
	<script>
		$mxm="";
		function bilibili_video($url) {
			if($mxm!=$url){
				$("#url").attr('src',$url);
				$mxm=$url;
			}
			$("#b_video").show(1000);
		}
		function no($id){
			$div=$("#b_video");
			if($id==1){//小化
				if(IsMobile()){
					$div.css("height","35%");
                  	$div.css("width","100%");
				}else{
					$div.css("height","70%");
                  	$div.css("width","70%");
				}
			}
			if($id==2){//全屏化
				$div.css("width","100%");
              	if(IsMobile()){
					$div.css("height","95%");
				}else{
				    $div.css("height","100%");
				}
			}
			if($id==3){//关闭播放
				$div.hide(1000);
			}
			}
      
      //判断是否是手机
    function IsMobile() {
        var isMobile = {
            Android: function () {
                return navigator.userAgent.match(/Android/i) ? true : false;
            },
            BlackBerry: function () {
                return navigator.userAgent.match(/BlackBerry/i) ? true : false;
            },
            iOS: function () {
                return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
            },
            Windows: function () {
                return navigator.userAgent.match(/IEMobile/i) ? true : false;
            },
            any: function () {
                return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
            }
        };
        return isMobile.any(); //true是移动设备
    }
	</script>
</html>